#ifndef __HTTP_H__
#define __HTTP_H__

#include "rio.h"

#define MAXMETHOD       16
#define MAXVERSION      16
#define MAXURI          1024
#define MAXTYPE         1024
#define MAXCGI          1024
#define MAXFILE         1024
#define MAXREMOTE       1024
#define MAXBUF          8192

typedef struct {
    char    method[MAXMETHOD]; 
    char    version[MAXVERSION];
    char    uri[MAXURI];
    char    content_type[MAXTYPE];
    int     content_len;
    int     request_over;
    char    remote_name[MAXREMOTE];
    char    remote_addr[MAXREMOTE];
    char    buf[MAXBUF];
    int     buf_offset;
} http_request;

typedef struct {
    char    buf[MAXBUF];
    int     size;
    int     offset;
} http_response;

int http_readrequest(http_request *, rio_t *);
int http_writeresponse(http_response *, int fd);

void http_serve(http_request *, http_response *);

#endif
